﻿
using AutoMapper;
using OP20.AutoMapper;
using OP20.Views.ST13;
using OP20.Views.ST14;
using OP20.Views.ST15;

namespace OP20.Extensions
{
    public static class ContainerExtensions
    {
        public static void AddViews(this IContainerRegistry services)
        {

            //新增部分
            services.Add<MainWindow, MainWindowViewModel>(AppViews.MainWindow);
            services.Add<AllStationView, AllStationViewModel>(AppViews.AllStationView);
            services.Add<MenuView, MenuViewModel>(AppViews.MenuView);
            services.Add<AlarmsManagerView, AlarmsManagerViewModel>(AppViews.AlarmsManagerView);
            services.Add<PingBiView, PingBiViewModel>(AppViews.PingBiView);
            services.Add<IOMonitorView, IOMonitorViewModel>(name: AppViews.IOMonitorView);
            services.Add<ProductStatisticView, ProductStatisticViewModel>(AppViews.ProductStatisticView);
            services.Add<HeightCheckView, HeightCheckViewModel>(AppViews.HeightCheckView);
            services.Add<WeightCheckView, WeightCheckViewModel>(AppViews.WeightCheckView);
            services.Add<PressureCheckView, PressureCheckViewModel>(AppViews.PressureCheckView);
            services.Add<LifeControlView, LifeControlViewModel>(AppViews.LifeControlView);
            services.Add<ContinuousNgView, ContinuousNgViewModel>(AppViews.ContinuousNgView);
            services.Add<AlarmsHistoryView, AlarmsHistoryViewModel>(AppViews.AlarmsHistoryView);
            services.Add<CycleTimeStatisticView, CycleTimeStatisticViewModel>(AppViews.CycleTimeStatisticView);

            services.Add<ST01View, ST01ViewModel>(AppViews.ST01View);
            services.Add<ST02View, ST02ViewModel>(AppViews.ST02View);
            services.Add<ST03View, ST03ViewModel>(AppViews.ST03View);
            services.Add<ST04View, ST04ViewModel>(AppViews.ST04View);
            services.Add<ST05View, ST05ViewModel>(AppViews.ST05View);
            services.Add<ST06View, ST06ViewModel>(AppViews.ST06View);
            services.Add<ST08View, ST08ViewModel>(AppViews.ST08View);
            services.Add<ST10View, ST10ViewModel>(AppViews.ST10View);
            services.Add<ST11View, ST11ViewModel>(AppViews.ST11View);
            services.Add<ST12View, ST12ViewModel>(AppViews.ST12View);
            services.Add<ST13View, ST13ViewModel>(AppViews.ST13View);
            services.Add<ST14View, ST14ViewModel>(AppViews.ST14View);
            services.Add<ST15View, ST15ViewModel>(AppViews.ST15View);

            services.Add<ST01CyManagerView, ST01CyManagerViewModel>(AppViews.ST01CyManagerView);
            services.Add<ST01DeviceManagerView, ST01DeviceManagerViewModel>(AppViews.ST01DeviceManagerView);
            services.Add<ST02CyManagerView, ST02CyManagerViewModel>(AppViews.ST02CyManagerView);
            services.Add<ST02DeviceManagerView, ST02DeviceManagerViewModel>(AppViews.ST02DeviceManagerView);
            services.Add<ST03CyManagerView, ST03CyManagerViewModel>(AppViews.ST03CyManagerView);
            services.Add<ST03DeviceManagerView, ST03DeviceManagerViewModel>(AppViews.ST03DeviceManagerView);
            services.Add<ST04CyManagerView, ST04CyManagerViewModel>(AppViews.ST04CyManagerView);
            services.Add<ST04ServoManagerView, ST04ServoManagerViewModel>(AppViews.ST04ServoManagerView);
            services.Add<ST05CyManagerView, ST05CyManagerViewModel>(AppViews.ST05CyManagerView);
            services.Add<ST05DeviceManagerView, ST05DeviceManagerViewModel>(AppViews.ST05DeviceManagerView);
            services.Add<ST06CyManagerView, ST06CyManagerViewModel>(AppViews.ST06CyManagerView);
            services.Add<ST06DeviceManagerView, ST06DeviceManagerViewModel>(AppViews.ST06DeviceManagerView);
            services.Add<ST08CyManagerView, ST08CyManagerViewModel>(AppViews.ST08CyManagerView);
            services.Add<ST08ServoManagerView, ST08ServoManagerViewModel>(AppViews.ST08ServoManagerView);
            services.Add<ST10CyManagerView, ST10CyManagerViewModel>(AppViews.ST10CyManagerView);
            services.Add<ST10DeviceManagerView, ST10DeviceManagerViewModel>(AppViews.ST10DeviceManagerView);
            services.Add<ST11CyManagerView, ST11CyManagerViewModel>(AppViews.ST11CyManagerView);
            services.Add<ST11DeviceManagerView, ST11DeviceManagerViewModel>(AppViews.ST11DeviceManagerView);
            services.Add<ST12CyManagerView, ST12CyManagerViewModel>(AppViews.ST12CyManagerView);
            services.Add<ST12DeviceManagerView, ST12DeviceManagerViewModel>(AppViews.ST12DeviceManagerView);
            services.Add<ST13CyManagerView, ST13CyManagerViewModel>(AppViews.ST13CyManagerView);
            services.Add<ST13DeviceManagerView, ST13DeviceManagerViewModel>(AppViews.ST13DeviceManagerView);
            services.Add<ST14CyManagerView, ST14CyManagerViewModel>(AppViews.ST14CyManagerView);
            services.Add<ST15CyManagerView, ST15CyManagerViewModel>(AppViews.ST15CyManagerView);
            services.Add<LoginView, LoginViewModel>(AppViews.LoginView);
        }


        public static void AddAutoMapper(this IContainerRegistry services)
        {
            services.RegisterSingleton<IAutoMapperProvider, AutoMapperProvider>();
            services.Register(typeof(IMapper), GetMapper);
        }


        #region 私有方法

        private static void Add<TView, TViewModel>(this IContainerRegistry containerRegistry, string name = null)
        {
            containerRegistry.RegisterForNavigation<TView, TViewModel>(name);
        }

        private static IMapper GetMapper(IContainerProvider container)
        {
            var provider = container.Resolve<IAutoMapperProvider>();
            return provider.GetMapper();
        }

        #endregion
    }
}
